<template>
	<view class="content reg-page">
		<view class="input-group">
			<view class="input-column border-bottom-1px" @click="toPost()">
				<text class="title">职位名称</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" disabled="true" placeholder="请选择职位名称" :value="position.jobName" />
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">学历</text>
				<view class="picker">
					<picker @change="bindPickerChange2" :value="position.requestEducation" :range-key="'dictValue'" :range="educations">
						<input class="padding-10" placeholder="请选择学历" :value="position.requestEducation" />
					</picker>					
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">经验要求</text>
				<view class="picker">
					<picker @change="bindPickerChange3" :value="position.requestExperience" :range-key="'dictValue'" :range="expRequires">
						<input placeholder="请选择经验要求" :value="position.requestExperience" />
					</picker>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">招聘类型</text>
				<view class="picker">
					<picker  @change="jobtypeChange3" :value="position.jobType" :range-key="'dictValue'" :range="jobType">
						<input placeholder="请选择经验要求" :value="position.jobType"/>
					</picker>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">薪资要求</text>
				<view class="picker">
					<picker @change="bindPickerChange" :value="position.salaryRang" :range-key="'dictValue'" :range="salaeyArray">
						<input placeholder="请选择薪资要求" :value="position.salaryRang" />
					</picker>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">1年多少薪</text>
				<view class="picker">
					<picker @change="salaryMonthChange" :value="position.salaryMonth" :range-key="'dictValue'" :range="SalaryMonth">
						<input placeholder="请选择多少薪" :value="position.salaryMonth" />
					</picker>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px" @click="toWorkContent(5)">
				<text class="title">职位描述</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" disabled="true" placeholder="请输入职位描述" v-model="position.jobDescription" />
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px" @click="toKeyword()">
				<text class="super-title">职位关键词</text>
				<view class="skill-item">					
					<input class="flex-1" disabled="true" placeholder="请选择职位关键词" v-model="position.keywords" />
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px" @click="selectAddress">
				<text class="title">工作地点</text>
				<view class="input-item">
					<input class="padding-10" placeholder="请选择工作地点" disabled="true" v-model="position.jobAddress" />
					<text class="yzb yzb-next"></text>
				</view>
				<text class="padding-width-10 text-color-grey text-size-base">{{ position.address }}</text>
			</view>
		</view>
		<view class="flex mar-top-30" v-if="job_id==''">
				<radio-group @change="radioGroup">
					<radio color="#84C0F4" :value="1" :checked="true" style="transform:scale(0.72);"></radio>
				</radio-group>
				<view class="agreement2">
					已同意并同意《***协议》
				</view>
			</view>
		
		<view class="btn-row row top-line">
			<button v-if="job_id" type="warn" class="btn-delete" @tap="remove">删除</button>
			<button type="primary" v-if="job_id" class="btn-save" :class="job_id ? 'width-55' : 'width-90'" @tap="register(2)">修改</button>
			<button type="primary" v-else class="btn-save" :class="job_id ? 'width-55' : 'width-90'" @tap="register(1)">提交</button>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import graceChecker from '@/common/graceChecker.js';
import formRuleConfig from '@/config/formRule.config.js';
export default {
	components: {
	},
	computed: {
		...mapState(['openId', 'customerInfo'])
	},

	data() {
		return {
			position:{
				enterpriseId:uni.getStorageSync('enterpriseId'),//企业id
				jobName:'',//职位名称
				professionId:'',//职位id
				requestEducation:'',//学历
				salaryRang:'',//薪资
				salaryMonth:'',//多少薪
				jobType:'',//招聘类型
				jobDescription:'',//职位描述
				keywords:'',//职位关键词
				requestExperience:'',//经验要求
				jobAddress:"",//工作地址	
				radioValue:1,
			},
			job_id: '',			
			current: 0,
			salaryValue: null,
			salaeyArray: [],
			expRequires:[],
			keys: [],
			educations: [],
			jobType:[],//招聘类型
			SalaryMonth:[],//多少薪
		};
	},
	onLoad(query) {	
		this.position.enterpriseId = uni.getStorageSync('enterpriseId')
		this.job_id = query.jobid
	},
	mounted() {
		let that = this	
		this.detailEnterprise_job()
		this.getEducational()
		this.getExpRequires()
		this.getPositionTypes()
		this.getSalary()
		this.getSalaryMonth()
		
	},
	onShow() {
		console.log(this.position)
	},
	methods: {	
		//获取详情
		async detailEnterprise_job() {
			var that = this
			this.$apis.detailEnterprise_job(that.job_id).then(res => {
				if(that.job_id){
					this.position = res.data
				}				
			})
		},
		//获取学历
		async getEducational(){
			let data = await this.$apis.getEducational();
			if(data){
				this.educations = data.data
			}
		},
		//经验要求		
		async getExpRequires(){
			let data = await this.$apis.getExpRequires();
			if(data){
				this.expRequires = data.data
			}
		},
		//get招聘类型		
		async getPositionTypes(){
			let data = await this.$apis.getPositionTypes();
			if(data){
				this.jobType = data.data
			}
		},
		//薪资范围		
		async getSalary(){
			let data = await this.$apis.getSalary();
			if(data){
				this.salaeyArray = data.data
			}
		},
		//多少薪		
		async getSalaryMonth(){
			let data = await this.$apis.getSalaryMonth();
			if(data){
				this.SalaryMonth = data.data
			}
		},
		//学历
		bindPickerChange2: function(e) {
			this.position.requestEducation = this.educations[e.target.value].dictValue;
		},
		//经验要求
		bindPickerChange3: function(e) {
			this.position.requestExperience = this.expRequires[e.target.value].dictValue;
		},
		//招聘类型
		jobtypeChange3: function(e) {
			this.position.jobType = this.jobType[e.target.value].dictValue;
		},
		//薪资要求
		bindPickerChange: function(e) {
			this.position.salaryRang=this.salaeyArray[e.target.value].dictValue;
		},
		//多少薪
		salaryMonthChange: function(e) {
			this.position.salaryMonth=this.SalaryMonth[e.target.value].dictValue;
		},		
		//地址选择
		selectAddress() {
			uni.chooseLocation({
				success: res => {					
					console.log(res.latitude)
					 console.log(res.longitude)

					if (res.address == '') {
						this.address = '请选择详细地址';
						return;
					}
					this.position.jobAddress = res.name;
					console.log(res.name)
				}
			});
		},
		//协议同意
		radioGroup(e) {
			this.position.radioValue = e.detail.value;
		},
		//选择关键词
		toKeyword(){
			this.$mRouter.push({
				route: this.$mRoutesConfig.keywordsa,
				query: {
					choicetype:1
				}
			});
		},
		//职位描述
		toWorkContent() {
			this.$mRouter.push({
				route: this.$mRoutesConfig.editProContent,
				query: {
					type: 5,
					content:this.position.jobDescription
				}
			});
		},
		//职位名称
		toPost() {
			this.$mRouter.push({
				route: this.$mRoutesConfig.post,
				query: {
					id: 1
				}
			});
		},
		
		// 点击注册按钮
		async register(type) {			
			var that = this			
			if(this.position.jobName == ''){
				uni.showToast({
					title: '请选择职位名称',
					icon: "none"
				});
				return false;
			}else if(this.position.requestEducation == ''){
				uni.showToast({
					title: '请选择学历',
					icon: "none"
				});
				return false;
			}else if(this.position.requestExperience == ''){
				uni.showToast({
					title: '请选择经验要求',
					icon: "none"
				});
				return false;
			}else if(this.position.jobType == ''){
				uni.showToast({
					title: '请选择招聘类型',
					icon: "none"
				});
				return false;
			}else if(this.position.salaryRang == ''){
				uni.showToast({
					title: '请选择薪资范围',
					icon: "none"
				});
				return false;
			}else if(this.position.salaryMonth == ''){
				uni.showToast({
					title: '请选择多少薪',
					icon: "none"
				});
				return false;
			}else if(this.position.jobDescription == ''){
				uni.showToast({
					title: '请输入职位描述',
					icon: "none"
				});
				return false;
			}else if(this.position.keywords == ''){
				uni.showToast({
					title: '请选择职位关键词',
					icon: "none"
				});
				return false;
			}else if(this.position.jobAddress == ''){
				uni.showToast({
					title: '请选择工作地点',
					icon: "none"
				});
				return false;
			}else{
				that.position.keywords.split(',')
				if(type == 1){
					let res = await this.$apis.addEnterprise_job(this.position);
					if (res) {
						uni.showToast({title: '提交成功'})
						setTimeout(function(){
							uni.navigateBack({
								delta: 1
							})
						},1200)	
					}
				}else{
					let res = await this.$apis.eidtEnterprise_job(this.position);
					if (res) {
						uni.showToast({title: '修改成功'})
						setTimeout(function(){
							uni.navigateBack({
								delta: 1
							})
						},1200)	
					}
				}
				
			}
			
		},

		async remove() {
			var that = this
			uni.showModal({
				title: '提示',
				content: '确定要删除吗？',
				success: res => {
					if (res.confirm) {
						this.$apis.deleteJob(that.job_id).then(res => {
							uni.showToast({
								title: "操作成功"
							})
							setTimeout(() => {
								this.$mRouter.back();
							}, 1000)
						})						
					}
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
input {
	width: 80%;
}
.input-group {
	border-radius: 10upx;
	margin-top: 10upx;
	overflow: hidden;
}

.input-row {
	display: flex;
	flex-direction: row;
	position: relative;
	background: #fff;
	justify-content: space-between;
	align-items: center;
	padding: 15upx 10upx;
}

.input-row .title {
	width: 25%;
	padding: 20upx 0;
	padding-left: 20upx;
	line-height: 50upx;
}

.border-bottom-1px {
	position: relative;

	&::after {
		position: absolute;
		z-index: 1;
		right: 0;
		bottom: 0;
		left: 20upx;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		background-color: #e2e2e2;
	}
}

.header {
	display: flex;
	flex-direction: column;
	.tip {
		font-size: $uni-font-size-sm;
		color: $font-color-666;
		margin-left: 20upx;
	}
}

.head-img {
	margin-right: 15upx;
	image {
		width: 160upx;
		height: 160upx;
		border-radius: 50%;
	}
}

radio-group {
	margin-right: 10upx;
}

.radio {
	margin-left: 20upx;
}

.input-column {
	display: flex;
	flex-direction: column;
	background-color: $bgcolor_white;
	padding: 30upx 20upx 10upx 20upx;

	.title {
		margin-left: 10upx;
	}

	.input-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.picker {
		padding: 20upx 0;
		margin-left: 10upx;
		position: relative;
		picker {
			font-size: $uni-font-size-lg;
			width: 100%;
			position: absolute;
		}
	}
	.yzb-next {
		float: right;
		color: $font-color-999;
	}
}

.content {
	background: $bgcolor_white;
	padding-bottom:200upx;
}

.btn-row {
	position: fixed;
	z-index: 999;
	bottom: 0upx;
	padding: 20upx 0;
	background-color: #ffffff;
	width: 100%;
	box-sizing: border-box;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
	box-sizing: content-box;
	.btn-delete {
		background-color: $bg-grey;
		height: 90upx;
		line-height: 90upx;
		font-size: $font-size-34;
		color: $font-color-333;
		width: 30%;
	}

	.btn-save {
		background-color: #84C0F4;
		height: 80upx;
		line-height: 80upx;
		font-size: $font-size-34;
		width: 90%;
		display: block;
		margin: 0 auto;
	}
	.width-55 {
		width: 55%;
	}

	.width-90 {
		width: 90%;
	}
}

.text-blue {
	color: $main-color;
	border: 1upx solid $main-color;
	background-color: $main-color;
	color: #ffffff;
}
.text-normal {
	color: $font-color-666;
	border: 1upx solid $border-color-base;
}

.skill-item {
	padding: 20upx;
	flex-wrap: wrap;
	display: flex;
	.skill-item-item{
		position: relative;
		margin-right: 20upx;
	}
	.item {
		font-size: $uni-font-size-sm;
		padding: 12upx 20upx;
		margin-right: 20upx;
		margin-bottom: 20upx;
		// background-color: $border-color-base;
		border-radius: 8upx;
		// color: $font-color-666;
	}
}

.img_delete {
	width: 45upx;
	height: 45upx;
	border-radius: 50%;
	background: rgba(234, 178, 178, 0.5);
	position: absolute;
	right: -15upx;
	top: -15upx;
	z-index: 10;
	align-items: center;
}
</style>
